<template>
  <div class="v-editor-proprtygroup-column g-jc-sb">
    <div class="g-flex-1 _list_scroll">
      <div
        v-for="(item, index) of valueList"
        :key="index"
        :class="{ _selected: selected && selectedModelId === item.id }"
        class="g-pd-l-8 g-one-line"
        style="border-bottom: 1px solid #ddd"
        @click="handleClickItem(item)"
        @contextmenu="propertyModelContextMenu($event, item)"
      >
        <span>
          <!-- <img style="margin-right: 4px;height: 16px;" :src="item.icon" /> -->
          <span v-if="item">{{ item }}</span>
        </span>
      </div>
    </div>

    <div
      v-if="selected && !row.readonly && !isModelDisabled"
      style="border-left: 1px solid #ddd; line-height: 14px"
      class="g-pd-4 g-flex-0"
    >
      <div>
        <img
          src="statics/icons/app/iconmore.png"
          class="g-pointer"
          @click="handleAdd"
        />
      </div>
      <!-- <div class="g-m-t-4">
        <img src="statics/icons/app/iconreduce.png" class="g-pointer" @click="handleRemove" />
      </div> -->
    </div>
  </div>
</template>
<script lang="ts" setup>
import { actionManager } from "@/action/ActionManager";
import { PropertyRow, ModelValue } from "../../types";
import { ref, Ref, computed, watch, inject } from "vue";
import { ActionKey } from "@/action/ActionKey";
import { PropertyGroupActions } from "@/modules/model/actions/model/PropertyGroupActions";
import { propertyModelContextMenu } from "../propertyUtil";
const isModelDisabled = inject("isModelDisabled") as Ref<boolean>;

/**
 *属性分组属性编辑器：column
 */
const props = defineProps<{
  row: PropertyRow;
  selected?: boolean;
}>();

const selectedModelId = ref("");

const valueList = computed(() => {
  return (props.row.value || []) as ModelValue[];
});

watch(
  () => props.selected,
  val => {
    if (val === false) {
      selectedModelId.value = "";
    }
  }
);

const handleAdd = () => {
  const action = actionManager.getAction(ActionKey.PropertyGroupActions) as PropertyGroupActions;
  action?.run(props.row);
};
function handleClickItem(item: ModelValue) {
  selectedModelId.value = item.id;
}
</script>
<style lang="scss">
@import "@/assets/css/theme.scss";
.v-editor-proprtygroup-column {
  // height: 100%;
  ._selected {
    color: $theme-color;
  }
  ._list_scroll {
    overflow-y: auto;
    &::-webkit-scrollbar {
      width: 8px;
      height: 8px;
    }
  }
}
</style>
